
<!-- saved from url=(0050)http://uva.onlinejudge.org/external/109/10940.html -->
<HTML><HEAD><META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><TITLE>Problem G: Throwing cards away II</TITLE>

</HEAD><BODY><H2>Problem G: Throwing cards away II </H2>

<IMG src="./acm-10940_files/p10940.jpg" vspace="20" hspace="20" align="right">
Given is an ordered deck of <EM>n</EM> cards numbered 1 to <EM>n</EM>
with card 1 at the top and card <EM>n</EM> at the bottom.
The following operation is performed as long as there are at least two cards
in the deck:
<P style="margin:20px">
Throw away the top card and move the card that is now on the top of the
deck to the bottom of the deck.
</P><P>
Your task is to find the last, remaining card.
</P><P>
Each line of input (except the last) contains a positive number
<EM>n</EM>&nbsp;&#8804;&nbsp;500000. The last line contains 0 and this
line should not be processed.  For each number from input produce
one line of output giving the last remaining card. Input will not contain
more than 500000 lines.


</P><H3>Sample input</H3>
<PRE>7
19
10
6
0
</PRE>


<H3>Output for sample input</H3>
<PRE>6
6
4
4
</PRE>

<HR>

<EM>Folklore, adapted by Piotr Rudnicki</EM>
</BODY></HTML>